package com.ojl.devs;

import java.io.File;
import java.util.ArrayList;

public class fileSys {

    public ArrayList<String> getFiles(String path)
    {
		return getFileFolderListEx(path, "FILES");
    }
    
    public ArrayList<String> getFolders(String path)
    {
		return getFileFolderListEx(path, "FOLDERS");
    }

    public ArrayList<String> getFileFolders(String path)
    {
		return getFileFolderListEx(path, "ALL");
    }
    
    public ArrayList<String> getFileFolderListEx(String path, String mode)
    {
    	/*
    	 * Get file folder list for given path
    	 * mode can be:
    	 * 1. FILES
    	 * 2. FOLDERS
    	 * 3. ALL
    	 */
    	
    	File dir = new File(path);
    	ArrayList<String> fList = new ArrayList<String>();
    	if (dir.isDirectory() && dir.exists())
    	{
    		for (String f: dir.list())
    		{
    			String fx = path + "\\" + f;
    			File nf = new File(fx);
    			if (mode.equals("FILES"))
    				if (nf.isFile())
    					fList.add(fx);
    			if (mode.equals("FOLDERS"))
    				if (nf.isDirectory())
    					fList.add(fx);
    			if (mode.equals("ALL"))
    				fList.add(fx);
    		}
    	}
		return fList;
    }    
    
	
}
